package main

import (
	"sync"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

func init() {
	setupORM()
	setupLogger()
}

func main() {
	logs.Debug("setup chat record sync")

	var group sync.WaitGroup
	group.Add(2)
	loadChatCron()
	loadChatErrCron()
	group.Wait()
}

func setupORM() {
	orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("mysqldatasource"))
	orm.SetMaxIdleConns("default", 5)
	orm.SetMaxOpenConns("default", 10)
}

func setupLogger() {

	if beego.BConfig.RunMode == "prod" {
		beego.SetLogFuncCall(true)
		beego.SetLogger(logs.AdapterConsole, `{"level":2}`)
		beego.SetLogger(logs.AdapterFile, `	{"filename":"./log/chat.log",
				"maxLines":1000,"maxsize":100000,
				"daily":true,"maxDays":15,"rotate":true,
			 	"perm":"0600","level":4
		}`)
	}

}
